package com.zmt.content.api;

import com.zmt.content.dto.BindTeachplanMediaDto;
import com.zmt.content.dto.SaveTeachPlanDto;
import com.zmt.content.dto.TeachplanDto;
import com.zmt.content.mapper.CourseTeacherMapper;
import com.zmt.content.mapper.TeachplanMediaMapper;
import com.zmt.content.po.CourseTeacher;
import com.zmt.content.service.TeachPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "课程计划业务接口", tags = "课程计划业务接口")
@RestController
public class TeachPlanController {

    @Autowired
    private TeachPlanService teachPlanService;

    //查询课程计划
    @ApiOperation("查询课程计划")
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public List<TeachplanDto> getTreeNodes(@PathVariable Long courseId) {
        List<TeachplanDto> result = teachPlanService.selectTreeNodes(courseId);
        return result;
    }

    @ApiOperation("课程计划的创建或修改")
    @PostMapping("/teachplan")
    public String saveTeachPlan(@RequestBody SaveTeachPlanDto teachPlanDto) {
        String s = teachPlanService.saveTeachPlan(teachPlanDto);
        return s;
    }

    @ApiOperation("课程计划删除接口")
    @DeleteMapping("/teachplan/{teachPlanId}")
    public String deleteTeachPlan(@PathVariable Long teachPlanId) {
        return teachPlanService.deleteTeachPlan(teachPlanId);
    }

    @ApiOperation("课程计划修改排序接口")
    @PostMapping("/teachplan/{type}/{teachPlanId}")
    public String moveOrder(@PathVariable(value = "type") String type, @PathVariable(value = "teachPlanId") Long teachPlanId) {
        teachPlanService.moveOrder(type, teachPlanId);
        return "操作成功";
    }

    @ApiOperation("课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    public void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto) {
        teachPlanService.associationMedia(bindTeachplanMediaDto);
    }

    @ApiOperation("查询课程计划是否可以试学")
    @GetMapping("/teachplan/{teachplanid}")
    public String getTeachPlanIsPreview(@PathVariable("teachplanid") Long teachplanid) {
        String result = teachPlanService.getTeachPlanIsPreview(teachplanid);
        return result;
    }

}